package xml;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import cuShapes.Arrow;
import cuShapes.PQShape;


public class ArrowCollectionAdapter extends XmlAdapter<ArrowListType, List<PQShape>> {
	// adapt original Java construct to a type, NotificationsType,
	// which we can easily map to the XML output we want
	public ArrowListType marshal(List<PQShape> arrowList) throws Exception {
		List<Arrow> arrows = new ArrayList<Arrow>();

		for (PQShape e : arrowList) {
			if (e instanceof Arrow) {
				arrows.add((Arrow) e);
			}
		}
		return new ArrowListType(arrows);
	}

	// reverse operation: map XML type to Java
	public List<PQShape> unmarshal(ArrowListType arrowList) throws Exception { 
		List<PQShape> arrows = new ArrayList<PQShape>();
        arrows.addAll(arrowList.getArrows());
        
        return arrows;
	}

}
